﻿using ManagoMes.Read.API.Applications.SupplierSearch;
using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.DTOs;
using MediatR;
using System.Runtime.ConstrainedExecution;
using System;
using MangoMes.Commont.Domain.RBACs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Commont.Domain.Suppliers;

namespace ManagoMes.Read.API.Applications.SupplierSearchRead
{
    public class SupplierClassSearchHandler : IRequestHandler<SupplierClassSearchCommand, ResultsDTO<SupplierClass>>
    {
        private readonly IBateRepository<SupplierClass> _supplierclassRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supplierclassRepository"></param>
        public SupplierClassSearchHandler(IBateRepository<SupplierClass> supplierclassRepository)
        {
            _supplierclassRepository = supplierclassRepository;
        }
        /// <summary>
        /// 供应商等级绑定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO<SupplierClass>> Handle(SupplierClassSearchCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapperHelper = new DapperHelper();
            SupplierClass supplierClass = new SupplierClass();
            ResultsDTO<SupplierClass> res = new ResultsDTO<SupplierClass> { Code = 0 };
            string conn = dapperHelper.MangoMesRead;
            string str = "select * from SupplierClass";
            res.Data = _supplierclassRepository.GetAll(str, supplierClass, conn).ToList();
            return res;
        }
    }
}
